﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using CellarDoor.Gui;
using CellarDoor.Gui.Elements;
using CellarDoor.Gui.Animation;

namespace CellarDoor.Gui.Demo.DemoScreens
{
    public class AnimationScreen : BaseScreen
    {
        public AnimationScreen(UiManager manager)
            : base(manager)
        {
            Initialize();
        }

        private void Initialize()
        {
            BuildEaseDemo(new Vector2(5, 5), Panel, EaseFunction.InQuad);
            BuildEaseDemo(new Vector2(5, 45), Panel, EaseFunction.OutQuad);
            BuildEaseDemo(new Vector2(5, 85), Panel, EaseFunction.InOutQuad);

            BuildEaseDemo(new Vector2(5, 125), Panel, EaseFunction.InCubic);
            BuildEaseDemo(new Vector2(5, 165), Panel, EaseFunction.OutCubic);
            BuildEaseDemo(new Vector2(5, 205), Panel, EaseFunction.InOutCubic);

            BuildEaseDemo(new Vector2(5, 245), Panel, EaseFunction.InSine);
            BuildEaseDemo(new Vector2(5, 285), Panel, EaseFunction.OutSine);
            BuildEaseDemo(new Vector2(5, 325), Panel, EaseFunction.InOutSine);
        }

        private void BuildEaseDemo(Vector2 offset, UiElement parent, EaseFunction function)
        {
            var panel = new UiPanel(parent);
            panel.Location = offset;
            panel.Width = 600 - offset.X * 2;
            panel.Height = 40;

            var button = new UiButton(panel);
            button.Text = function.ToString();
            button.Tag = function;
            button.Top = 5;
            button.Left = 5;
            button.Width = 150;
            button.Height = 30;

            var ball = new UiPanel(panel);
            ball.ElementName = "SlideBallH";
            ball.Top = 5;
            ball.Left = 155;
            ball.Width = 30;
            ball.Height = 30;

            button.Click += (s, e) =>
            {
                ball.Top = 5;
                ball.Left = 155;
                ball.SlideTo(new Vector2(panel.Width - offset.X - ball.Width, ball.Top), 2000, function);
            };
        }
    }
}
